## Generalized Reed--Solomon codes

# import os 
# os.chdir('C:\\Users\\usuario\\ownCloud\\public_html\\CC2')
# # Current extension patch to CC
# from CC_x import *
from PyM import *

def GRS(h,a,k):
    n = len(h)
    if len(a)!=n: return 'GRS error: length mismatch'
    C = AC(h,a,n-k)
    V = alternant_matrix(h,a,n-1)
    h1 = left_kernel(V)[0]
    G = alternant_matrix(h1,a,k)
    C._G = G
    return C 

# Examples

K = Zn(7)
n = 6; k = 3

h = geometric_series(4>>K,6)
a = [element(j,K) for j in range(1,n+1)]


C = GRS(h,a,k)

show(a_(C))
show(h_(C))
show(H_(C))
show(K_(C))

show(H_(C))

# Checking the control condition
show( G_(C)*transpose(H_(C)) )





